package pzl.com.library.listener;

import android.util.Log;
import android.view.MotionEvent;

import pzl.com.library.chart.BaseChart;
import pzl.com.library.chart.LineChart;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-25]
 */
public class LineTouchListener extends ChartTouchListener {
    public static final String TAG = "LineTouchListener";
    private LineChart mLineChart;
    float unitPX;

    public LineTouchListener(BaseChart baseChart) {
        super(baseChart);

        mLineChart = (LineChart) mBaseChart;
        mLineChart.getXBounds().initMinVisibleIndex(0);
        unitPX = 20f;
        int width = 720;
        mLineChart.getXBounds().initVisibleIndexRange((int) (width / unitPX));

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        Log.d(TAG, "onSingleTapUp");
        return super.onSingleTapUp(e);
    }

    @Override
    public void onLongPress(MotionEvent e) {
        Log.d(TAG, "onLongPress");
        super.onLongPress(e);
    }

    @Override
    public boolean onScroll(MotionEvent eTouchDown, MotionEvent eLastMove, float distanceX, float distanceY) {
        Log.d(TAG, "onScroll distanceX=" + distanceX + ",distanceY=" + distanceY);
        super.onScroll(eTouchDown, eLastMove, distanceX, distanceY);

        mLineChart.getXBounds().setMinVisibleIndex((int) (mSumScrollX / 20f));

        mBaseChart.scrollTo((int) mSumScrollX, (int) mSumScrollY);
        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        Log.d(TAG, "onFling velocityX=" + velocityX + ",velocityY=" + velocityY);
        return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public void onShowPress(MotionEvent e) {
        Log.d(TAG, "onShowPress");
        super.onShowPress(e);
    }

    @Override
    public boolean onDown(MotionEvent e) {
        Log.d(TAG, "onDown");
        return super.onDown(e);
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        Log.d(TAG, "onDoubleTap");
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        Log.d(TAG, "onDoubleTapEvent");
        return super.onDoubleTapEvent(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        Log.d(TAG, "onSingleTapConfirmed");
        return super.onSingleTapConfirmed(e);
    }

    @Override
    public boolean onContextClick(MotionEvent e) {
        Log.d(TAG, "onContextClick");
        return super.onContextClick(e);
    }

    @Override
    protected void onFlingAnim() {
        Log.d(TAG, "onFlingAnim");

        mLineChart.getXBounds().setMinVisibleIndex((int) (mSumScrollX / 20f));

        mBaseChart.scrollTo((int) mSumScrollX, (int) mSumScrollY);
    }

}
